import { Toast } from 'vant'

export default {
  data() {
    return {
      pageNo: 1,
      pageSize: 10,
      totalSize: 0,
      tableData: [],
      refreshLoading: true,
      loading: false,
      finished: false
    }
  },
  created() {
    this.onRefresh()
  },
  mounted() {
    const that = this
    window.onscroll = function() {
      const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
      const height = document.body.clientHeight
      const scrollHeight = document.body.scrollHeight
      if ((scrollTop + height + 30) >= scrollHeight) {
        that.pageNo++
        if (that.pageNo > 1) {
          if (that.tableData.length >= that.totalSize) return Toast('暂无更多')
        }
        that.getList()
      }
    }
  },
  beforeDestroy() {
    window.onscroll = null
  },
  methods: {
    onRefresh() {
      this.pageNo = 1
      this.getList()
    },
    getQueryParams() {
      return {
        pageNo: this.pageNo,
        pageSize: this.pageSize
      }
    }
  }
}
